package com.sunriz.motordrive.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


/**
 * ClassName: WebConfig
 * Package: com.sunriz.motordrive.config
 * Description:
 *
 * @Author BuTang
 * @Create 2024/5/9 15:42
 * @Version 1.0
 */
@Slf4j
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                //允许哪些域访问
                .allowedOriginPatterns("*")
                //允许哪些方法访问
                .allowedMethods("GET","POST","PUT","DELETE","HEAD","OPTIONS")
                //是否允许携带cookie
                .allowCredentials(true)
                //设置浏览器询问的有效期
                .maxAge(3600)
                .allowedHeaders("*");
    }
}
